import org.apache.commons.lang3.math.NumberUtils;
import org.junit.Test;
import org.springframework.util.StringUtils;

import java.text.SimpleDateFormat;
import java.time.LocalDate;
import java.time.LocalDateTime;
import java.time.LocalTime;
import java.time.format.DateTimeFormatter;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;

/**
 * Created by zhoum on 2018/1/8.
 */
public class DataTest {

    @Test
    public void test() throws InterruptedException {
        Long date = new Date().getTime();
        System.out.println(date);
        Thread.sleep(1 * 60 * 1000);
        System.out.println((System.currentTimeMillis() - date) < 1 * 60 * 1000);

    }

    @Test
    public void test2() throws InterruptedException {
        for (int i = 0; i < 3; i++) {
            System.out.println(System.currentTimeMillis());
        }

    }

    @Test
    public void test3() {
        SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss:SSS");
        System.out.println(format.format(new Date(1543803626368L)));
    }


    @Test
    public void getIndex() {
        List<String> list = new ArrayList<>();
        String format = LocalDate.now().format(DateTimeFormatter.ofPattern("yyyy-MM"));
        format = "API_LOG_INDEX" + format;
        list.add(format);
        format = LocalDate.now().plusMonths(-1).format(DateTimeFormatter.ofPattern("yyyy-MM"));
        format = "API_LOG_INDEX" + format;
        list.add(format);
        System.out.println(list);
    }

    @Test
    public void getIndex2() {
        //生成最新的流程编码
        SnowFlakeShortUrl snowFlake = new SnowFlakeShortUrl(2, 1);
        String cc = "OMSInboundSJ20200825102247036";
        String code = "";
        char[] charArray = cc.toCharArray();
        for (int i = 0; i < charArray.length; i++) {
            char c = charArray[i];
            if (NumberUtils.isNumber((c + ""))) {
                cc = cc.substring(0, i);
                code = cc + snowFlake.nextId();
                break;
            }
        }
        if (StringUtils.isEmpty(code)) {
            code = cc + snowFlake.nextId();
        }
        System.out.println(code);
    }

    @Test
    public void getIndex3() {
        LocalDateTime lastMonth = LocalDateTime.now().plusMonths(-1).with(LocalTime.MIN);
        System.out.println(lastMonth);
    }
}
